import DataEdit from '@/components/base/DataEdit';
import { DefaultDate, UpdateDiviPro, UpdateZSRQ } from '@/services/commCRUD';
import { Button, Col, message, Row } from 'antd';
import PageHeader from '@/components/page/PageHeader';
import { format } from '@/utils/datetime';
const controls: API.Control[] = [
  { name: 'day', label: '追溯天数', type: 'number', grid: 12 / 24, width: 200 },
];

const controls2: API.Control[] = [
  { name: 'dateString', label: '利润追溯日期', type: 'date', grid: 12 / 24, width: 200 },
];
const BaseClfhForm: React.FC = () => {
  const submit = async (vals: Record<string, any>) => {
    UpdateZSRQ(vals.day)
      .then(function () {
        message.info('修改成功');
      })
      .catch(function (ex) {
        console.log('请求出错', ex);
      });
  };
  const submit2 = async (vals: Record<string, any>) => {
    UpdateDiviPro(format(vals.dateString, 'yyyy-MM-dd'))
      .then(function () {
        message.info('处理成功');
      })
      .catch(function (ex) {
        console.log('请求出错', ex);
      });
  };
  return (
    <PageHeader>
      <Row>
        <Col span={24}>
          <DataEdit
            showType="inner"
            layout="inline"
            grid={false}
            title="设置追溯天数"
            onSumit={submit}
            controls={controls}
            renderButtons={(p) => {
              return [
                <Button type="primary" key="1" onClick={() => p.form?.submit?.()}>
                  设置追溯天数
                </Button>,
                <Button
                  type="default"
                  key="1"
                  onClick={() => {
                    DefaultDate()
                      .then(function (data: string) {
                        message.info('追溯日期为：' + data + '.');
                      })
                      .catch(function (ex) {
                        console.log('请求出错', ex);
                      });
                  }}
                >
                  查看追溯天数
                </Button>,
              ];
            }}
          />
        </Col>
      </Row>
      <Row>
        <Col span={24}>
          <div style={{ color: 'red', marginLeft: 400 }}>
            <br />
            <br />
            <br />
            <br />
            注意：
            <br />
            此功能在帐户关系修改和考核参数修改时执行, 默认追溯为60天；
            <br />
            如果考核参数修改影响到以前月份的考核结果, 需要调用此功能；
            <br />
            此功能执行需要较长时间，在执行期间不要进行帐户关系修改和参数修改操作。
            <br />
            <br />
          </div>
          <div style={{ marginLeft: 400 }}>
            <DataEdit
              showType="inner"
              layout="inline"
              title="处理分户修改"
              grid={false}
              keyColName="ID"
              controls={controls2}
              onSumit={submit2}
              renderButtons={(p) => {
                return [
                  <Button type="primary" key="1" onClick={() => p.form?.submit?.()}>
                    处理分户修改
                  </Button>,
                ];
              }}
            />
          </div>
        </Col>
      </Row>
    </PageHeader>
  );
};

export default BaseClfhForm;
